from django.db import models
from django.utils import timezone
import datetime
# Create your models here.
class Poll(models.Model):
    question = models.CharField(max_length = 200)
    pub_date = models.DateField('date publisher')
    pub_person = models.CharField(max_length = 30)

    def is_published_recently(self):
        offset = timezone.now() - datetime.timedelta(1)
        return self.pub_date >= offset.date()
    is_published_recently.admin_order_field = 'pub_date'
    is_published_recently.boolean = True
    is_published_recently.description = 'Published recently?'

    def __unicode__(self):
        return self.question

class Choice(models.Model):
    poll = models.ForeignKey(Poll)
    choice_text = models.CharField(max_length = 100)
    votes = models.IntegerField(default = 0)

    def __unicode__(self):
        return '%s,%d'%(self.choice_text,self.votes)